$(function() {
    $('.js-check-btn').hover(function() {
        $(this).addClass('vivify pulsate');
    }, function() {
        $(this).removeClass('vivify pulsate');
    });
    $('.js-search-tips-close').click(function() {
        $('.js-search-tips').fadeOut(500);
    })

    function searchFn() {
        if ($('.js-search-val').val().trim() == '') {
            $('.js-search-tips').fadeIn(500);
            setTimeout(function() {
                $('.js-search-tips').fadeOut(500);
            }, 3000)
        } else {
            if ($('.js-select>span').attr('data-id') == '50017') {
                let _url = $('.js-select>span').attr('data-href')
                let _val = $('.js-search-val').val();
                window.location.href = _url + '?queryStr=' + _val;
            } else if ($('.js-select>span').attr('data-id') == '50018') {
                let _url = $('.js-select>span').attr('data-href')
                let _val = $('.js-search-val').val();
                window.location.href = _url + '?query=' + _val + '&secQuery=&actualQuery=' + _val + '&searchType=2&docType=全部&isGroup=isGroup&targetFieldLog=全部字段&fromHome=true'
            } else if ($('.js-select>span').attr('data-id') == '50019') {
                let _url = $('.js-select>span').attr('data-href')
                let _val = $('.js-search-val').val();
                window.location.href = _url + '?request=' + _val + '&func=find-m&find_code=WRD&FIND_BASE=NLC01&FIND_BASE=NLC09'
            } else {
                let _url = $('.js-select>span').attr('data-href')
                let _val = $('.js-search-val').val();
                window.location.href = _url + '?searchWord=' + _val
            }
        }

    }
    $('.js-check-btn').click(function() {
        searchFn()
    })
    $(document).keyup(function(e) {
        let curKey = e.which;
        if (curKey == 13) {
            searchFn()
        }
    });
    $('.js-select p a').click(function(e) {
        e.preventDefault();
        let _name = $(this).parent('p').siblings('span').text();
        let _dataUrl = $(this).parent('p').siblings('span').attr('data-href');
        let _dataId = $(this).parent('p').siblings('span').attr('data-id');
        $(this).parent('p').siblings('span').html($(this).text() + '<i class="view-transition"></i>')
        $(this).parent('p').siblings('span').attr('data-href', $(this).attr('data-href'))
        $(this).parent('p').siblings('span').attr('data-id', $(this).attr('data-id'))
            // $(this).html('<i></i>' + _name);
            // $(this).attr('data-href', _dataUrl)
            // $(this).attr('data-id', _dataId)
    });
    var swiper1 = new Swiper('.swiper-container-1', {
        autoplay: true,
        loop: true,
        pagination: {
            el: '.swiper-pagination',
            clickable: true,
        },
        navigation: {
            nextEl: '.button-next',
            prevEl: '.button-prev',
        },
    });
    var swiper2 = new Swiper('.swiper-container-2', {
        loop: true,
        autoHeight: true,
        slidesPerView: 'auto',
        navigation: {
            nextEl: '.button-next-act',
            prevEl: '.button-prev-act',
        },
    });
    var swiper3 = new Swiper('.swiper-container-exhibion', {
        loop: true,
        autoplay: true,
        autoHeight: true,
        pagination: {
            el: '.swiper-pagination',
        },
    });

    var swiper4 = new Swiper('.swiper-container-flink', {
        loop: true,
        autoplay: true,
        autoHeight: true,
        slidesPerView: 'auto',
        preventClicks: false, //默认true
    });
    $('.sub-links ul li').hover(function() {
        $(this).find('img').addClass('vivify hitLeft');
    }, function() {
        $(this).find('img').removeClass('vivify hitLeft');
    });
    $('.swiper-container-flink .swiper-slide').hover(function() {
        swiper4.autoplay.stop();
    }, function() {
        swiper4.autoplay.start();
    })
    $('.swiper-container-exhibion .swiper-slide').hover(function() {
        swiper3.autoplay.stop();
    }, function() {
        swiper3.autoplay.start();
    })
    $('.index-lastest-bar .swiper-slide .swiper-slide-into').hover(function() {
        $(this).children('.sub-title').addClass('sub-title-cur')
        $(this).children('.cover-full-title').addClass('cover-full-title-cur')
    }, function() {
        $(this).children('.sub-title').removeClass('sub-title-cur')
        $(this).children('.cover-full-title').removeClass('cover-full-title-cur')
    });
    // $('.resouce-list li').hover(function() {
    //     $(this).children('i').addClass('flip-horizontal-bottom')
    //     $(this).children('dl').addClass('flip-horizontal-bottom')
    // }, function() {
    //     $(this).children('i').removeClass('flip-horizontal-bottom')
    //     $(this).children('dl').removeClass('flip-horizontal-bottom')
    // })
    $('.resouce-list-btm dl').hover(function() {
        $(this).find('.org').fadeOut();
        $(this).find('.anim').fadeIn();
    }, function() {
        $(this).find('.org').fadeIn();
        $(this).find('.anim').fadeOut();
    })

    // $('.js-content').each(function(ele) {
    //     var _txt = $(ele).siblings('dd').children('h5').children('span').text()
    //     $(ele).children('img').attr('alt', _txt)
    // })
    // $('.swiper-container-2 .swiper-slide').each(function(ele) {
    //     var _txt = $(ele).find('h5.sub-title').children('span').text()
    //     $(ele).children('div').children('img').attr('alt', _txt)
    // })
    // $('.container-exhibion .swiper-slide').each(function(ele) {
    //     var _txt = $(ele).find('dl').find('dd').find('.tips').children('h5').text()
    //     $(ele).find('dl').find('dt').children('img').attr('alt', _txt)
    // })
    var swipermuseum = new Swiper(".index-museum-swiper", {
        direction: "vertical",
        slidesPerView: "auto",
        freeMode: true,
        scrollbar: {
            el: ".swiper-scrollbar",
        },
        mousewheel: true,
    });
    $('.index-museum-into .index-museum-tabs .swiper .swiper-slide p').eq(0).addClass('cur')
    $('.index-museum-tacs ul li').eq(0).show()
    $('.index-museum-into .index-museum-tabs .swiper .swiper-slide p').hover(function() {
        let _curI = $('.index-museum-into .index-museum-tabs .swiper .swiper-slide p').index($(this));
        console.log('_curI', _curI)
        $('.index-museum-into .index-museum-tabs .swiper .swiper-slide p').removeClass('cur')
        $(this).addClass('cur')
        $('.index-museum-tacs ul li').hide()
        $('.index-museum-tacs ul li').eq(_curI).show()
    })
    $('.time-bar').each(function(i, ele) {
        if ($(ele).children('b').text().trim() == '' || $(ele).children('span').text().trim() == '') {
            $(ele).text('')
        }
    })

    $('.activities ul li').hover(function() {
        if (!$(this).hasClass('on')) {
            $('.activities ul li').removeClass('on');
            $(this).addClass('on')
        }
    })

    /*图片轮换的js*/
    /*********初始设置**************/
    //获取节点对象
    var imgOuter = $('.wrap'); //所有图片所处的容器
    var imgDiv = $('.pic'); //各图片所在的div容器
    //设置部分初始值与计算
    var timeId = null; //记录如片轮换的定时器，自动轮换与鼠标控制切换时用到
    var edgeDistance = 90; //记录相邻图片错开的距离90
    var imgNow = imgDiv.length - 1; //记录当前显示的第几张图片，此处为默认值0
    var imgMouse = 0; //记录鼠标停留在第几张图片上
    var imgOuterWidth = imgOuter.width(); //记录所有图片最外层容器的宽度，计算即将显示第一张图片时的，其他图片移动的距离
    /**********方法*************/
    /*图片自动轮换的方法主体*/
    function autoSlide() {


        console.log(imgNow)
            //显示第一张图片和显示后面图片的移动方式不同
        if (imgNow == 0) { //显示第一张图片

            for (var i = 1; i < imgDiv.length; i++) {
                imgDiv.eq(i).animate({ 'left': edgeDistance * i + 'px' }, 700);
            }
        } else { //显示第一张之外的任意图片
            imgDiv.eq(imgNow).animate({ 'left': imgOuterWidth - edgeDistance * (imgDiv.length - imgNow) - 60 + 'px' }, 700);
        }
        //计算第几张图片开始运动
        if (imgNow == 0) {
            imgNow = imgDiv.length - 1;
            imgDiv.removeClass('on')
            imgDiv.eq(imgNow).addClass('on')
        } else {
            imgNow--;
            imgDiv.removeClass('on')
            imgDiv.eq(imgNow).addClass('on')
        }

    }
    /*鼠标影响图片轮换的方法主体*/
    function mouseSlide() {
        imgDiv.removeClass('on')
        imgDiv.eq(imgMouse).addClass('on')
        console.log(imgMouse, imgNow)
        if (imgMouse > imgNow) {
            for (var i = imgNow + 1; i <= imgMouse; i++) {
                console.log("a",i)
               // imgDiv.eq(i).animate({ 'left': edgeDistance * i + 'px' }, 300);
                imgDiv.eq(i).stop().animate({ 'left': edgeDistance * i + 'px' }, 700);
            }
        } else {
            for (var i = imgNow; i > imgMouse; i--) {
                console.log("b",i)
             //   imgDiv.eq(i).animate({ 'left': imgOuterWidth - edgeDistance * (imgDiv.length - i) - 60 + 'px' }, 300);
                imgDiv.eq(i).stop().animate({ 'left': imgOuterWidth - edgeDistance * (imgDiv.length - i) - 60 + 'px' }, 700);
            }
        }
        //700
        imgNow = imgMouse;
    }

    /*图片自动轮换*/
    timeId = setInterval(autoSlide, 3000);
    imgDiv.hover(function() {
        //鼠标移入，停止自动轮换
        clearInterval(timeId);
        //获得鼠标停留在第几张图片，调用鼠标事件的方法
        imgMouse = $(this).index();
        console.log("timeId",timeId,imgMouse,imgNow)
        if (imgMouse != imgNow) {
            mouseSlide();
        }
    }, function() {
        //鼠标离开，继续自动轮换
        timeId = setInterval(autoSlide, 3000);
    })
})